/*
 * Author: 李波(Edwin Lee)
 * Date: 2024-07-07 20:12:38
 * FilePath: /code/C/String/main.cpp
 * LastEditTime: 2024-08-02 12:38:43
 * version: 1.0
 * Description: 
 */
#include <stdio.h>
#include <cstring>
#include <stdlib.h>
int main()
{
	
	//测试字符串的初始化和strlen sizeof函数
	char string[10];
	strcpy(string,"goodjob");
	char str[128] = {'h','e',0,'o','l','l'};
	char str1[6] = "hello";
	char* p = "goodday";
	printf("%s\n",string);
	printf("%ld\n",strlen(str));
	printf("%ld\n",sizeof(str));
	printf("%s\n", str1);
	printf("length of p is:%ld\n", strlen(p));//结果是7

	
	//测试中文的strlen,中文一个字strlen=2(gbk格式）,12(UTF8)
	char chinese[] = "你好中国";
	printf("%s的长度是：%ld,sizeof是%ld\n", chinese, strlen(chinese), sizeof(chinese));
	

	/*
	//测试strcat函数
	char str2[20];
	str2[0] = 'h';
	str2[1] = '\0';
	char str3[5] = "good";
	strcat(str2, str3);//结果表明str2必须是以\0结尾的字符串才能组合，组合结果会在最后添加\0，如果组合后长度超出str2，则没有\0在最后
	printf("%s\n", str2);

	//测试strncat函数
	char str4[20];
	str4[0] = 'h';
	str4[1] = '\0';
	char str5[7] = "good\n5";
	strncat(str4, str5,10);//结果表明str4必须是以\0结尾的字符串才能组合，组合结果会在最后添加\0，如果组合后长度超出str2，则没有\0在最后,\n也会被复制
	printf("%s\n", str4);
	*/


	return 0;
}